import pygame
import time

from pygame.locals import *

class RenWu():
    def __init__(self,screen):
        self.x = 350
        self.y = 460
        self.screen =screen
        self.img_name = "D:/python/小游戏/tupian/gou.jpg"
        self.img = pygame.image.load(self.img_name).convert()
        self.speed = 10
        self.num = []
    def display(self):
        self.screen.blit(self.img,(self.x,self.y))
    def move_xia(self):
        self.y += 2
    def zuobiao(self):
        a = self.x+64
        b =self.y +64
        self.num.append(b)
        if b < 0 or b>600:
            exit()
                # return b
    def panduan(self):
        return self.y
    def key_control(self):
        # 监听键盘事件
        key_pressed = pygame.key.get_pressed()

        if key_pressed[K_w] or key_pressed[K_UP] or key_pressed[K_SPACE] :
            self.y -= 20


        if key_pressed[K_s] or key_pressed[K_DOWN]:
            self.y += self.speed

        if key_pressed[K_a] or key_pressed[K_LEFT]:
            self.x -= self.speed

        if key_pressed[K_d] or key_pressed[K_RIGHT]:
            self.x += self.speed

class jianzhu():
    def __init__(self,screen):
        self.x = 1150
        self.y = 0
        self.screen = screen
        self.num_a = []
        self.num_b  = []


    def move(self):
        self.x -= 3
        time.sleep(0.01)
    def move_again(self):
        if self.x <= 100:
            self.x = 1150


class jianzhu_zilei(jianzhu):
    def img(self):
        self.img_name = 'D:/python/小游戏/tupian/zhuzi.png'
        self.img = pygame.image.load(self.img_name).convert()

    def display(self):
        self.screen.blit(self.img,(self.x,self.y))


class jianzhu_zilei3(jianzhu):
    def __init__(self, screen):
        super().__init__(screen)
        self.x = 1000
        self.y = 0

    def img(self):
        self.img_name = 'D:/python/小游戏/tupian/zhuzi1.png'
        self.img = pygame.image.load(self.img_name).convert()

    def display(self):
        self.screen.blit(self.img, (self.x, self.y))

class jianzhu1():
    def __init__(self,screen):
        self.x = 1000
        self.y = 380
        self.screen = screen

    def move(self):
        self.x -= 3
        time.sleep(0.01)
    def move_again(self):
        if self.x <= -20:
            self.x = 1150


class Jianzhu_zilei1(jianzhu1):
    def img(self):
        self.img_name = 'D:/python/小游戏/tupian/zhuzi1.png'
        self.img = pygame.image.load(self.img_name).convert()

    def display(self):
        self.screen.blit(self.img,(self.x,self.y))



class jianzhu_zilei2(jianzhu1):
    def __init__(self,screen):
        super().__init__(screen)
        self.x = 780
        self.y = 420

    def img(self):
        self.img_name = 'D:/python/小游戏/tupian/zhuzi1.png'
        self.img = pygame.image.load(self.img_name).convert()

    def display(self):
        self.screen.blit(self.img, (self.x, self.y))
    def zuobiao(self):

        a=self.x
        b =self.y

        if a == 400 and b in (420,538):
            exit()
class Game_over():

    def __init__(self,screen):
        self.x= 400
        self.y = 200
        self.screen =screen


    def img(self):
        self.img_name = 'D:/python/小游戏/tupian/gameover.png'
        self.img = pygame.image.load(self.img_name).convert()
    def display(self):
        self.screen.blit(self.img, (self.x, self.y))




def key_control(player_tmp):

    for event in pygame.event.get():

        # 判断是否是点击了退出按钮
        if event.type == QUIT:
            print("exit")
            exit()
        # 判断是否是按下了键
        elif event.type == KEYDOWN:
            # 检测按键是否是a或者left
            if event.key == K_a or event.key == K_LEFT:
                print('left')
                player_tmp.move_shang()
             # 检测按键是否是d或者right
            elif event.key == K_d or event.key == K_RIGHT:
                print('right')
                player_tmp.move_xia()


def main():



    screen = pygame.display.set_mode((1200,538),0,32)
    background = pygame.image.load('D:/python/小游戏/tupian/background.jpg')
    pygame.display.set_caption('跳一跳')
    hero = RenWu(screen)


    hero3 = Jianzhu_zilei1(screen)
    hero4 = jianzhu_zilei2(screen)

    hero2 = jianzhu_zilei(screen)
    hero5 = jianzhu_zilei3(screen)
    hero6 = Game_over(screen)


    while True:
        screen.blit(background, (0,0))
        hero.key_control()

        hero.display()
        key_control(RenWu)
        RenWu.move_xia(hero)
        RenWu.zuobiao(hero)
        RenWu.panduan(hero)

        Game_over.img(hero6)
        # hero6.display()
        #子类1

        jianzhu_zilei.img(hero2)
        hero2.move()
        hero2.display()
        hero2.move_again()
        #hero2.zuobiao()


        #子类2
        Jianzhu_zilei1.img(hero3)

        hero3.display()
        hero3.move()
        hero3.move_again()
        #hero3.zuobiao()
        #子类3
        jianzhu_zilei2.img(hero4)
        hero4.move()
        hero4.display()
        hero4.move_again()
        # hero4.zuobiao()
        #子类4
        jianzhu_zilei3.img(hero5)
        hero5.move()
        hero5.move_again()
        hero5.display()
        # hero5.zuobiao()
        liat_1 =[]
        for i in range(187):
            i += 1
            liat_1.append(i)
        if hero2.x == 400 and hero.y in liat_1:
            exit()
        liat_2 = []
        for i in range(194):
            i += 1
            liat_2.append(i)
        if hero5.x == 400 and hero.y in liat_2:
            exit()
        liat_3 = []
        for i in range(118):
            i += 1
            liat_3.append(i+356)

        if hero4.x == 402 and hero.y in liat_3:
            exit()
        liat_4 = []
        for i in range(158):
            i += 1
            liat_4.append(i+316)
        print(hero3.x)
        if hero3.x == 400 and hero.y in liat_4:
            exit()

        pygame.display.update()


if __name__ == '__main__':
    main()
